#include <stdio.h>
#include <stdlib.h>
#include "estructuras.h"

extern unsigned int* generar_tabla_apariciones(unsigned char *buf, unsigned int size);
extern codigo_t* generar_tabla_codigos(unsigned int *tabla_apariciones);
extern int calcular_longitud_codificacion(unsigned int *tabla_apariciones, codigo_t *tabla_codigo);
extern int generar_codificacion(unsigned char *src_buf, unsigned int src_size, unsigned char *dst_buf, unsigned int dst_size, codigo_t *tabla_codigos);
int comprimir_buffer(unsigned char *scr_buf, unsigned int scr_size, unsigned char **dst_buf, unsigned int *dst_size, codigo_t **tabla_codigos, unsigned int *long_codificacion);

int main(){
	unsigned int src_size = 8;
	unsigned char *src_buf = (unsigned char *)malloc(src_size);
	
	int i;
	for (i = 0; i<src_size/4; i++){
		src_buf[i] = 0;
	}
	
	for (i = src_size/4; i<src_size/2; i++){
		src_buf[i] = 1;
	}
	
	for (i = src_size/2; i<src_size; i++){
		src_buf[i] = 2;
	}
	
	unsigned char *dst_buf;
	dst_buf = NULL;
	unsigned int dst_size;
	codigo_t *tabla_codigos;
	tabla_codigos = NULL;
	unsigned int long_codif;
	
	int res = comprimir_buffer(src_buf, src_size, &dst_buf, &dst_size, &tabla_codigos, &long_codif);
	
	printf("El resultado de comprimir_buffer %d \n", res);
	
	printf("El tam del dst_buff %u \n", dst_size);
	
	printf("El long codif %u \n", long_codif);
	
	printf("Esta es la tabla de codigos \n");
	
	for (i=0; i<256; i++){
		if(tabla_codigos[i].valido){
			printf("Esta es la posicion %i \n", i);
			mostrar_codigo_t(&tabla_codigos[i]);
		}
	}
	
	return 0;
}
